package BBDD;

import java.sql.*;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import DAO.AlumnoDAO;
import DAO.ProfesorDAO;

public class ManageProfesor {

	private Connection conn;
	private Statement pstmt;
	private ResultSet rs;
	private String query;
	private ManageDB abreConn;
	private Vector<ProfesorDAO> profesor = new Vector<ProfesorDAO>();

	public ManageProfesor() {
		abreConn = new ManageDB();
		conn = abreConn.getConnection();		
		abreConn.OpenDB();
	}

	public void loadDataProfesor(String query) {
		this.query = query;
		conn = abreConn.getConnection();
		
		try {
			pstmt = conn.createStatement();
			rs = pstmt.executeQuery(query);		
			
			while (rs.next()) {
				int idprofesor = rs.getInt(1);
				String dni= rs.getString(2);
				String nombre = rs.getString(3);
				String apellido1 = rs.getString(4);
				String apellido2 = rs.getString(5);
				int telefono = rs.getInt(6);
				setProfesor(new ProfesorDAO(idprofesor, dni, nombre, apellido1,
						apellido2, telefono));

			}

		} catch (SQLException ex) {
			Logger.getLogger(ManageProfesor.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {
			try {
				rs.close();
				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
	}

	public void updateProfesor(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {
			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageProfesor.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {
				pstmt.close();
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public void deleteProfesor(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageProfesor.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public String getOldQuery() {
		return query;
	}

	public Vector<ProfesorDAO> getProfesor() {
		return profesor;
	}

	public void setProfesor(ProfesorDAO profesor) {
		this.profesor.add(profesor);
	}

}
